/************************************************************************************
 RC Hobby Stream
 Twitter automatic feeder

 First version developed with support of Mapelgate Media

"RC Hobby Stream" is protected by the copyright law
© 2011 Enrico Miglino / Tech Consulting (enrico.miglino@ovi.com)
Distributed under the LGPL 3.0 license.

This file is part of "RC Hobby Stream".

    "RC Hobby Stream" is free software: you can redistribute it
    and/or modify it under the terms of the Lesser GNU General Public License
    as published by the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    "RC Hobby Stream" is distributed in the hope that it
    will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    Lesser GNU General Public License for more details.

    You should have received a copy of the Lesser GNU General Public License
    along with "RC Hobby Stream".
    If not, see <http://www.gnu.org/licenses/>.
************************************************************************************/

import QtQuick 1.0
import QtWebKit 1.0

// On/Off button to manage link toolbars.
Item {
    id: container   // Button container

    signal clicked  // Managed signal for button handler
    property string text    // Button description
    property bool keyUsing: false

    // Aliases for the source property of the two images of the button
    property alias buttonOff: buttonImage.source
    property alias buttonOn: pressed.source

    // Definition of the couple of images for button and button-pressed
    BorderImage {
        id: buttonImage

        opacity: 1
        width: container.width; height: container.height
    }
    BorderImage {
        id: pressed

        opacity: 0
        width: container.width; height: container.height
    }

    // Definition of the clickable area for the button
    MouseArea {
        id: mouseRegion

        anchors.fill: buttonImage
        onClicked: { container.clicked(); }
    }

    Text {
        id: btnText // Text description for the button
        color: "#D0D0D0"    // Text color
        anchors.verticalCenter: buttonImage.verticalCenter
        anchors.left: buttonImage.right; anchors.leftMargin: 8
        text: container.text; style: Text.Raised; styleColor: "black"
        textFormat: Text.RichText
        font.pointSize: 8; font.bold: true
    }

    // States managed for the button
    states: [
        State {
            name: "Pressed"
            when: mouseRegion.pressed == true
            PropertyChanges { target: pressed; opacity: 1 }
        },
        // Focused state is not managed actually. For future use only.
        State {
            name: "Focused"
            when: container.activeFocus == true
        }
    ]
}
